package com.example.ssm.Controller;

import com.example.ssm.Bean.Account;
import com.example.ssm.service.imp.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.io.IOException;
import java.util.List;

/**
 * @create 2022-03-2022/3/6-9:49
 */
@Controller
public class AccountController {

    @Autowired
    private AccountService accountService;
    //保存
    @RequestMapping(value = "/saveAccount",produces = "text/html;charset=UTF-8")
    public  String save(Account account) throws IOException {
        accountService.save(account);
        return "AccountList";
    }
    //查询
    @RequestMapping(value = "/findAllAccount",produces = "text/html;charset=UTF-8")
    public ModelAndView findALL() throws IOException {
       List<Account> AccountList= accountService.findAll();
       ModelAndView modelAndView =new ModelAndView();
       modelAndView.addObject("list",AccountList);
       modelAndView.setViewName("AccountList");
      //for (Account a:AccountList){System.out.println(a);}
       return modelAndView;
    }

    @RequestMapping("/success")
    public String success(){
        return "unit/success";
    }

}
